import { HYEventStore } from 'hy-event-store'
import { getRankings } from '../service/music-api'

const rankingNames={
  0:"newRanking",
  1:"hotRanking",
  2:"originalRanking",
  3:"upRanking"
}

const rankingStore = new HYEventStore({
  state:{
    newRanking:{},//新歌榜
    hotRanking:{},//热歌榜
    originalRanking:{},//原创榜
    upRanking:{}//飙升榜
  },
  actions:{
    getRankingDatas(ctx){//发送请求拿到巅峰榜的数据
       // 0: 新歌榜 2: 原创榜 3: 飙升榜
      //根据传入的不同的id，拿到相应的数据
      for(let i = 0;i < 4; i++){
       getRankings(i).then(res=>{
        const rankingName = rankingNames[i]
        ctx[rankingName] = res.playlist 
        //ctx[rankingName]相当于ctx.rankingName
      })
      }    
    }
  }
})
export { rankingStore,rankingNames}